<template>
	<view class="container">
		<u-navbar :border-bottom="false" :background="{ background: 'linear-gradient(to right, #A36BFF 0%, #6D4BBE 100%)' }" title="预约详情" title-color="#fff" back-icon-color="#fff"></u-navbar>
		
		<view class="signup-top">
			<view class="signup-top__head">
				<view class="title">{{detail.course.name}}（{{detail.teacher.name}}）</view>
				<view>{{detail.start_time}}-{{detail.end_time}}</view>
			</view>
			<view class="signup-top__card">
				已签 <text class="col1">{{detail.appoint_sign_count}}</text> 人 / 预约 <text class="col2">{{detail.appoint_count}}</text> 人
			</view>
		</view>
		<!-- mescroll-body start -->
		<mescroll-body ref="mescrollRef" :down="downOption" :up="upOption" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="signup-list">
				<view class="signup-list__item" v-for="(item,index) in dataList" :key="index">
					<view class="wd-flex item-head">
						<image class="avatar" :src="item.user.avatar" mode="aspectFill"></image>
						<view class="wd-flex-cell">
							<view class="title">{{ item.user.username }}</view>
							<view class="title">{{ item.vip.name }}</view>
							<view class="info" v-if="item.user_vip.type == 2">扣减次数：<text>{{ item.vip_card_num }}次</text></view>
							<!-- <view class="info" v-if="item.user_vip.type == 2">剩余次数：<text>{{ item.vip_card_num }}次</text></view> -->
							<view class="info">有效期至：<text>{{ item.user_vip.expire_in_text }}</text></view>
						</view>
						<!-- <view class="action">
							<u-button v-if="item.status==1&&item.sign_status==1" shape="circle" @click="sign_up(index,item.id)" size="mini" :ripple="true" :custom-style="{width:'145rpx',height:'54rpx',background: 'linear-gradient(131deg, #A36BFF 0%, #6D4BBE 100%)',color:'#fff',fontSize:'24rpx'}">签到</u-button>
							<u-button v-if="item.status==1&&item.sign_status==1" shape="circle" @click="cancel_appointment(index,item.id)" size="mini" :ripple="true" :plain="true" :custom-style="{width:'145rpx',height:'54rpx',marginTop:'16rpx',fontSize:'24rpx'}">取消预约</u-button>
							<u-button v-if="item.sign_status==2" shape="circle" size="mini" :ripple="true" :plain="true" :custom-style="{width:'145rpx',height:'54rpx',marginTop:'16rpx',fontSize:'24rpx'}">已签到</u-button>
							<u-button v-if="item.status==0" shape="circle" size="mini" :ripple="true" :plain="true" :custom-style="{width:'145rpx',height:'54rpx',marginTop:'16rpx',fontSize:'24rpx'}">已取消</u-button>
						</view> -->
					</view>
					<view class="item-foot">
						备注<text>{{ item.note }}</text>
					</view>
				</view>
			</view>
		</mescroll-body>
		<!-- mescroll-body end -->
		
		<!-- <view class="signup-add" @click="add_appointment">
			<u-icon name="plus" color="#fff" size="30"></u-icon>
			<text>添加代约</text>
		</view> -->
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				course_arrangement_id:0,
				detail:{},
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon: '../../../../static/images/icon_empty-class.png',
						tip: '还没有会员预约，请点击右下角按钮代约课程'
					}
				},
				dataList: [],
			}
		},
		onLoad(options){
			this.course_arrangement_id = options.arrangement_id || 0;
			this.getDetail();
		},
		methods: {
			getDetail(){
				var that = this;
				var course_arrangement_id = that.course_arrangement_id;
				that.$core.get({url:'fitness.manage/arrangement_detail',data:{type:'sign',arrangement_id:course_arrangement_id},success:(ret)=>{
					that.detail = ret.data
				}});
			},
			
			/*上拉加载的回调*/
			upCallback(page) {
				var that = this;
				let postData = {
					arrangement_id: that.course_arrangement_id,
				    page: page.num, // 页码, 默认从1开始
				    pagesize: page.size // 每页数据条数
				};
				that.$core.post({url:'fitness.teacher/appointment_lists',data:postData,success:(ret)=>{
					if(page.num == 1) that.dataList = []; //如果是第一页需手动制空列表
					that.dataList = that.dataList.concat(ret.data.data); //追加新数据
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					that.mescroll.endSuccess(ret.data.data.length);
				}});
			},
			
			sign_up(index,course_appointment_id){
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认签到？',
					success: function(res){
						if(res.confirm){
							var option = {
								tip_status: true,
								method: 'POST',
								tips: 'loading',
								url: 'api/manage/sign',
								data: {course_appointment_id:course_appointment_id}
							};
										
							http.common_request(that,option,function(data){
								
								if(data.code){
									http.toast(data.msg);
									let dataList = that.dataList;
									dataList[index].sign_status = 2;
									that.dataList = dataList;
								}
							})
						}
					}
				})
			},
			
			cancel_appointment(index,course_appointment_id){
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认取消？',
					success: function(res){
						if(res.confirm){
							var option = {
								tip_status: true,
								method: 'POST',
								tips: 'loading',
								url: 'api/manage/cancel_appointment',
								data: {course_appointment_id:course_appointment_id}
							};
										
							http.common_request(that,option,function(data){
								
								if(data.code){
									http.toast(data.msg);
									let dataList = that.dataList;
									dataList[index].status = 0;
									that.dataList = dataList;
								}
							})
						}
					}
				})
			},
			
			add_appointment(){
				var course_arrangement_id = this.course_arrangement_id;
				uni.navigateTo({
					url: '/pages/manage/addEnroll/addEnroll?course_arrangement_id='+course_arrangement_id
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background: #F6F6F6;
	}
	.signup-top {
		position: relative;
		&__head {
			display: flex;
			align-items: center;
			padding: 24rpx;
			padding-bottom: 70rpx;
			background: linear-gradient(to right, #A36BFF 0%, #6D4BBE 100%);
			line-height: 45rpx;
			font-size: 30rpx;
			color: #FFFFFF;
			border-radius: 0 0 24rpx 24rpx;
			.title {
				flex: 1;
				margin-right: 20rpx;
				overflow: hidden;
			}
		}
		&__card {
			margin: 0 24rpx;
			margin-top: -44rpx;
			padding: 26rpx 24rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			line-height: 38rpx;
			font-size: 26rpx;
			color: #333333;
			text {
				padding: 0 8rpx;
				&.col1 {
					color: #FF4E00;
				}
				&.col2 {
					color: #6D4BBE;
				}
			}
		}
	}
	.signup-list {
		padding: 24rpx;
		&__item {
			margin-bottom: 16rpx;
			padding: 0 24rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			.item-head {
				padding: 30rpx 0;
			}
			.avatar {
				display: block;
				margin-right: 35rpx;
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
			}
			.title {
				line-height: 48rpx;
				font-size: 34rpx;
				font-weight: 500;
				color: #333333;
			}
			.info {
				line-height: 40rpx;
				font-size: 26rpx;
				color: #333333;
			}
			.action {
				margin-left: 24rpx;
				display: flex;
				flex-direction: column;
			}
			.item-foot {
				border-top: 1rpx #F7F7F7 solid;
				display: flex;
				padding: 20rpx 0;
				line-height: 30rpx;
				font-size: 22rpx;
				color: #333333;
				text {
					flex: 1;
					overflow: hidden;
					text-align: right;
					color: #999999;
				}
			}
		}
	}
	
	.signup-add {
		position: fixed;
		right: 24rpx;
		bottom: 150rpx;
		z-index: 99;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 96rpx;
		height: 96rpx;
		background: linear-gradient(to right, #A36BFF 0%, #6D4BBE 100%);
		box-shadow: 0 4rpx 14rpx 0 rgba(109,75,190,0.2);
		border-radius: 99px;
		
		image {
			display: block;
			width: 32rpx;
			height: 32rpx;
		}
		text {
			display: block;
			margin-top: 3rpx;
			text-align: center;
			line-height: 22rpx;
			font-size: 16rpx;
			color: #FFFFFF;
		}
	}
</style>